import type { UserType } from '@/types/user'
import { USER_ROLE, NOT_LOGIN, ADMIN_ROLE } from './accessEnum'

export const checkAuth = (loginUser: UserType, needAccess: string) => {
  const userRole = loginUser.userRole

  //如果当前页面需要用户登录
  if (needAccess === USER_ROLE) {
    if (userRole === NOT_LOGIN) return false
  }

  //如果当前页面需要管理员
  if (needAccess === ADMIN_ROLE) {
    if (userRole !== ADMIN_ROLE) return false
  }

  return true
}
